<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
$(function() {
    var urlPrefix = "${pageContext.request.contextPath}/api/";
    var tenderAPI = new TenderAPI({urlPrefix : urlPrefix});
    var tenderId = "<s:property value='tenderId' />";
    var tenderData = {};
    
  	//for debug
	try{throw ''} catch(e){}
	
    initialize();
	
	function initialize() {
	    
	    tenderAPI.detail({
			onSuccess : function(data) {
			    tenderData = data.tender;
			    $('#tender_detail #tender_title').text(tenderData.tender_title);
			    $('#tender_detail #enroll_start_date').text(tenderData.enroll_start_date);
			    $('#tender_detail #enroll_end_date').text(tenderData.enroll_end_date);
			    $('#tender_detail #tender_end_date').text(tenderData.tender_end_date);
			    $('#tender_detail #publish_result_date').text(tenderData.publish_result_date);
			    $('#tender_detail #contact_name').text(tenderData.contact_name);
			    $('#tender_detail #contact_tel').text(tenderData.contact_tel);
			    $('#tender_detail #tender_pattern_name').text(tenderData.tender_pattern_name);
			    $('#tender_detail #content_description').html(tenderData.content_description);
			    $('#tender_detail #vendor_requirement').html(tenderData.vendor_requirement);
			},
			onAPIError : function(status, errors) {
			},
			onServerError : function(jqXHR, textStatus, errorThrown) {
			}
		},
		{
			param: JSON.stringify({
			    tender_id: tenderId
			})
		});
	    
		$('#tender_detail #product_grid').datagrid({
		    url: '${pageContext.request.contextPath}/api/TenderProductSearchAPI.json',
		    title: '招标产品',
		    iconCls: 'icon-product',
		    columns: [[
                {field:'product_name', title:'产品名称', width:240, align:'left', halign:'center', resizable:false},
                {field:'quantity', title:'数量', width:75, align:'right', halign:'center', resizable:false},
                {field:'unit', title:'单位', width:75, align:'center', halign:'center', resizable:false},
                {field:'product_description', title:'产品描述', width:345, align:'left', halign:'center', resizable:false}
            ]],
            fit: true,
            striped: true,
            rownumbers: true,
            singleSelect: true,
            autoRowHeight: false,
            idField: 'product_id',
            queryParams: {
            	param: JSON.stringify({
            		tender_id: tenderId
            	})
            },
            loadFilter: function(data) {
            	var datax = {};
            	if (data && data.products && $.isArray(data.products)) {
            	    datax = {
        	            total: data.products.length,
                	    rows: data.products
                	};
            	} else {
            	    datax = {
            	        total: 0,
            	        rows: []
            	    };
            	}
            	return datax;
            },
    		onSelect : function (rowIndex, rowData){
    		    $('#tender_detail #product_grid').datagrid('unselectRow', rowIndex);
    		}
		});
	}
});	
</script>
<div id="tender_detail">
  <table id="tender_table" class="edit_table" style="margin-bottom: 10px;">
    <tr height="28">
      <th width="77">招标名称</th>
      <td colspan="7"><label id="tender_title"></label></td>
    </tr>
    <tr height="28">
      <th width="77">报名开始日</th>
      <td width="100" align="center"><label id="enroll_start_date"></label></td>
      <th width="77">报名截止日</th>
      <td width="100" align="center"><label id="enroll_end_date"></label></td>
      <th width="77">投标截止日</th>
      <td width="100" align="center"><label id="tender_end_date"></label></td>
      <th width="77">中标公布日</th>
      <td width="100" align="center"><label id="publish_result_date"></label></td>
    </tr>
    <tr height="28">
      <th width="77">联系人</th>
      <td width="100"><label id="contact_name"></label></td>
      <th width="77">联系电话</th>
      <td width="100"><label id="contact_tel"></label></td>
      <th width="77">招标方式</th>
      <td colspan="3" valign="middle"><label id="tender_pattern_name"></label></td>
    </tr>
    <tr height="28">
      <th width="77">内容说明</th>
      <td colspan="7"><label id="content_description"></label></td>
    </tr>
    <tr height="28">
      <th width="77">供应商要求</th>
      <td colspan="7"><label id="vendor_requirement"></label></td>
    </tr>
  </table>
  <div style="width: 776px; height: 249px;">
    <table id="product_grid"></table>
  </div>
</div>